# Maintainer: Nick Østergaard <oe.nick at gmail dot com>

_realname=oce
pkgbase=mingw-w64-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-${_realname}
pkgver=0.18.3
pkgrel=3
pkgdesc="Open CASCADE Community Edition: patches/improvements/experiments contributed by users over the official Open CASCADE library."
url="https://github.com/tpaviot/oce"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
license=('LGPLv2.1')
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}-git")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake")
depends=("${MINGW_PACKAGE_PREFIX}-freetype")
#depends=('intel-tbb' 'gl2ps' 'freeimage' 'tk')
source=(https://github.com/tpaviot/${_realname}/archive/OCE-${pkgver}.tar.gz unicode.patch)
# 99_oce.sh 99_oce.conf)
install=oce-${CARCH}.install
sha256sums=('c553d6a7bf52f790abc3b6bb7a1e91a65947e92a426bb1a88a11960c31f0966c'
            'bff7743d03258a532578c642a8140a0583fcff3bd05cc0a81a8bef00f2629c83')

prepare() {
  cd "${srcdir}/oce-OCE-${pkgver}"
  patch -p3 -i "${srcdir}"/unicode.patch
}

build() {
  [[ -d "build-${MINGW_CHOST}" ]] && rm -rf "build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"

  #flags="$flags -DOCE_MULTITHREAD_LIBRARY:STRING=TBB"
  #flags="$flags -DOCE_WITH_GL2PS=ON"
  #flags="$flags -DOCE_WITH_FREEIMAGE=ON"
  #flags="$flags -DOCE_DRAW=ON"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_PREFIX_PATH=;-DCMAKE_INSTALL_PREFIX=;-DOCE_INSTALL_PREFIX=;-DOCE_INSTALL_CMAKE_DATA_DIR=;-DOCE_INSTALL_BIN_DIR=;-DOCE_INSTALL_LIB_DIR=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
      -G"MSYS Makefiles" \
      -DCMAKE_PREFIX_PATH=${MINGW_PREFIX} \
      -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
      -DOCE_INSTALL_PREFIX=${MINGW_PREFIX} \
      -DOCE_INSTALL_BIN_DIR=bin \
      -DOCE_INSTALL_LIB_DIR=lib \
      -DOCE_INSTALL_CMAKE_DATA_DIR=${MINGW_PREFIX}/lib/oce \
      -DOCE_AUTOINSTALL_DEPENDENT_LIBS=OFF \
      -DCMAKE_C_USE_RESPONSE_FILE_FOR_OBJECTS=1 \
      -DCMAKE_CXX_USE_RESPONSE_FILE_FOR_OBJECTS=1 \
      -DCMAKE_C_USE_RESPONSE_FILE_FOR_INCLUDES=1 \
      -DCMAKE_CXX_USE_RESPONSE_FILE_FOR_INCLUDES=1 \
      -DCMAKE_C_RESPONSE_FILE_LINK_FLAG=@ \
      -DCMAKE_CXX_RESPONSE_FILE_LINK_FLAG=@ \
      ../oce-OCE-${pkgver}

  make
}

package() {
  cd build-${MINGW_CHOST}
  make DESTDIR="${pkgdir}" install
  install -Dm644 ${srcdir}/oce-OCE-${pkgver}/LICENSE_LGPL_21.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE_LGPL_21.txt"
  install -Dm644 ${srcdir}/oce-OCE-${pkgver}/OCCT_LGPL_EXCEPTION.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/OCCT_LGPL_EXCEPTION.txt"

  #install -m644 -D "${srcdir}/99_oce.conf" -t "${pkgdir}/etc/ld.so.conf.d"
  #install -m755 -D "${srcdir}/99_oce.sh" -t "${pkgdir}/etc/profile.d"
}

# vim:set ts=2 sw=2 et:
